package com.pk.platform.business.privilege.web;

import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.core.web.GenericAction;
import com.pk.platform.business.privilege.service.IMenuService;
import com.pk.platform.business.privilege.vo.MenuVO;
import com.pk.platform.domain.privilege.Menu;
import com.pk.platform.util.constant.Constant;

public class MenuAction extends GenericAction {

	private IMenuService menuService;
	
	private Menu menu = new Menu();
	
	private Menu parentMenu = new Menu();
	
	private MenuVO mvo = new MenuVO();
	
	private String tree;
	
	private String moduleType;
	
	private boolean hasChildren = false;
	
	private List<Menu> menuList = new ArrayList<Menu>();
	
	public String toAddMenu()
	{
		if(Constant.SAME.equals(moduleType))
		{
			Menu thisMenu = menuService.queryMenuById(menu.getId());
			parentMenu = menuService.queryMenuById(thisMenu.getParentId());
			if(parentMenu == null)
			{
				parentMenu = new Menu();
				parentMenu.setMenuName("主菜单");
				parentMenu.setId(new Long(1));
			}
		}
		else if(Constant.NEXT.equals(moduleType))
		{
			parentMenu = menuService.queryMenuById(menu.getId());
		}
		return SUCCESS;
	}

	public String addMenu()
	{
		menuService.addMenu(menu);
		return SUCCESS;
	}
	
	public String toUpdateMenu()
	{
		menuList = menuService.queryMenuListExcludeItself(menu.getId());
		menu = menuService.queryMenuById(menu.getId());
		return SUCCESS;
	}
	
	public String updateMenu()
	{
		menuService.updateMenu(menu);
		return SUCCESS;
	}
	
	public String delMenu()
	{
		hasChildren = menuService.hasChildren(menu.getId());
		if(hasChildren == false)
		{
			menuService.delMenu(menu.getId());
		}
		return SUCCESS;
	}
	
	public String queryAllMenuTree()
	{
		tree = menuService.getAllMenuTree();
		return SUCCESS;
	}

	public IMenuService getMenuService() {
		return menuService;
	}

	public void setMenuService(IMenuService menuService) {
		this.menuService = menuService;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public MenuVO getMvo() {
		return mvo;
	}

	public void setMvo(MenuVO mvo) {
		this.mvo = mvo;
	}

	public String getTree() {
		return tree;
	}

	public void setTree(String tree) {
		this.tree = tree;
	}

	public String getModuleType() {
		return moduleType;
	}

	public void setModuleType(String moduleType) {
		this.moduleType = moduleType;
	}

	public Menu getParentMenu() {
		return parentMenu;
	}

	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}

	public boolean isHasChildren() {
		return hasChildren;
	}

	public void setHasChildren(boolean hasChildren) {
		this.hasChildren = hasChildren;
	}

	public List<Menu> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<Menu> menuList) {
		this.menuList = menuList;
	}
	
}
